﻿/*
   Copyright 2012 Dmitry Bratus

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Flower.Logging
{
    public sealed class Log
    {
        private readonly string _source;

        internal Log(string source)
        {
            _source = source;
        }

        public void Trace(string message)
        {
            var logManager = LogManager.Instance;

            if (logManager != null)
            {
                logManager.Dispatch
                (
                    new LogEntry
                    {
                        Message = message,
                        Severity = LoggingLevel.Trace,
                        Source = _source
                    }
                );
            }
        }

        public void Info(string message)
        {
            var logManager = LogManager.Instance;

            if (logManager != null)
            {
                logManager.Dispatch
                (
                    new LogEntry
                    {
                        Message = message,
                        Severity = LoggingLevel.Info,
                        Source = _source
                    }
                );
            }
        }

        public void Warning(string message)
        {
            var logManager = LogManager.Instance;

            if (logManager != null)
            {
                logManager.Dispatch
                (
                    new LogEntry
                    {
                        Message = message,
                        Severity = LoggingLevel.Warning,
                        Source = _source
                    }
                );
            }
        }

        public void Error(string message)
        {
            var logManager = LogManager.Instance;

            if (logManager != null)
            {
                logManager.Dispatch
                (
                    new LogEntry
                    {
                        Message = message,
                        Severity = LoggingLevel.Error,
                        Source = _source
                    }
                );
            }
        }

        public void Fatal(string message)
        {
            var logManager = LogManager.Instance;

            if (logManager != null)
            {
                logManager.Dispatch
                (
                    new LogEntry
                    {
                        Message = message,
                        Severity = LoggingLevel.Fatal,
                        Source = _source
                    }
                );
            }
        }

        public void Trace(Func<string> message)
        {
            var logManager = LogManager.Instance;

            if (logManager != null)
            {
                logManager.Dispatch
                (
                    new LogEntry
                    {
                        MessageFunc = message,
                        Severity = LoggingLevel.Trace,
                        Source = _source
                    }
                );
            }
        }

        public void Info(Func<string> message)
        {
            var logManager = LogManager.Instance;

            if (logManager != null)
            {
                logManager.Dispatch
                (
                    new LogEntry
                    {
                        MessageFunc = message,
                        Severity = LoggingLevel.Info,
                        Source = _source
                    }
                );
            }
        }

        public void Warning(Func<string> message)
        {
            var logManager = LogManager.Instance;

            if (logManager != null)
            {
                logManager.Dispatch
                (
                    new LogEntry
                    {
                        MessageFunc = message,
                        Severity = LoggingLevel.Warning,
                        Source = _source
                    }
                );
            }
        }

        public void Error(Func<string> message)
        {
            var logManager = LogManager.Instance;

            if (logManager != null)
            {
                logManager.Dispatch
                (
                    new LogEntry
                    {
                        MessageFunc = message,
                        Severity = LoggingLevel.Error,
                        Source = _source
                    }
                );
            }
        }

        public void Fatal(Func<string> message)
        {
            var logManager = LogManager.Instance;

            if (logManager != null)
            {
                logManager.Dispatch
                (
                    new LogEntry
                    {
                        MessageFunc = message,
                        Severity = LoggingLevel.Fatal,
                        Source = _source
                    }
                );
            }
        }

        public void Warning(string message, Exception ex)
        {
            var logManager = LogManager.Instance;

            if (logManager != null)
            {
                logManager.Dispatch
                (
                    new LogEntry
                    {
                        Message = message,
                        Severity = LoggingLevel.Warning,
                        Exception = ex,
                        Source = _source
                    }
                );
            }
        }

        public void Error(string message, Exception ex)
        {
            var logManager = LogManager.Instance;

            if (logManager != null)
            {
                logManager.Dispatch
                (
                    new LogEntry
                    {
                        Message = message,
                        Severity = LoggingLevel.Error,
                        Exception = ex,
                        Source = _source
                    }
                );
            }
        }

        public void Fatal(string message, Exception ex)
        {
            var logManager = LogManager.Instance;

            if (logManager != null)
            {
                logManager.Dispatch
                (
                    new LogEntry
                    {
                        Message = message,
                        Severity = LoggingLevel.Fatal,
                        Exception = ex,
                        Source = _source
                    }
                );
            }
        }

        public void Warning(Func<string> message, Exception ex)
        {
            var logManager = LogManager.Instance;

            if (logManager != null)
            {
                logManager.Dispatch
                (
                    new LogEntry
                    {
                        MessageFunc = message,
                        Severity = LoggingLevel.Warning,
                        Exception = ex,
                        Source = _source
                    }
                );
            }
        }

        public void Error(Func<string> message, Exception ex)
        {
            var logManager = LogManager.Instance;

            if (logManager != null)
            {
                logManager.Dispatch
                (
                    new LogEntry
                    {
                        MessageFunc = message,
                        Severity = LoggingLevel.Error,
                        Exception = ex,
                        Source = _source
                    }
                );
            }
        }

        public void Fatal(Func<string> message, Exception ex)
        {
            var logManager = LogManager.Instance;

            if (logManager != null)
            {
                logManager.Dispatch
                (
                    new LogEntry
                    {
                        MessageFunc = message,
                        Severity = LoggingLevel.Fatal,
                        Exception = ex,
                        Source = _source
                    }
                );
            }
        }
    }
}
